home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: netcom.com!smryan
- From: smryan@netcom.com (@#$%!?!)
- Subject: Re: About union
- Message-ID: <smryanDpqCB7.F0w@netcom.com>
- Organization: The Programmer formerly known as S M Ryan
- X-Newsreader: TIN [version 1.2 PL1]
- References: <4kfj5g$24n@dewey.csun.edu>
- Date: Fri, 12 Apr 1996 03:28:19 GMT
- Sender: smryan@netcom21.netcom.com
-
- : (void) printf("The value of integer is %d\n", myUnion.integer);
- : (void) printf("The value of floating is %f\n\n", myUnion.floating);
-
- The current bits in the union are interpreted according to the type of
- the member you use. myUnion.integer interprets the bits as an int,
- myUnion.floating interprets the exact same bit pattern as a float. The
- compiler make no attempt coerce the bits or verify the union was assigned
- and accessed with the same types.
-
- : (void) printf("The value of \"cast\" is %f\n", (float) myUnion.integer);
-
- Integer coerced to float as expected.
-
- : (void) printf("The value of \"magic\" is %f\n\n", myUnion.integer);
-
- printf expects a double parameter with an %f descriptor.
-
- : (void) printf("The meaning of life ``%d''\n", (int) myUnion.floating);
-
- The bits are interpreted as a float and then coerced to int.
-
- --
- The Queen, amused, in quiet power, | smryan@netcom.com PO Box 1563
- will draw the son to darkenned bower. | Cupertino, California
- Her face is fair, her fragrance rare, | (xxx)xxx-xxxx 95015
- with woven webs for wayward flower. | I don't use no smileys
-